//
//  MessageSingleton.m
//  Chamleon-template
//
//  Created by james on 15/9/6.
//
//

#import "MessageSingleton.h"
static MessageSingleton *sharedMessageSingleton = nil;
@implementation MessageSingleton


+ (id)sharedInstance
{
    static dispatch_once_t pred = 0;
    __strong static id sharedMessageSingleton = nil;
    dispatch_once(&pred, ^{
        sharedMessageSingleton = [[self alloc] init]; // or some other init method
    });
    return sharedMessageSingleton;
}
+(id)allocWithZone:(struct _NSZone *)zone{
    //调用dispatch_once保证在多线程中也只被实例化一次
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMessageSingleton = [super allocWithZone:zone];
    });
    return sharedMessageSingleton;
}

/**第3步: 保证init初始化时都相同*/
+(instancetype)sharedTool{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMessageSingleton = [[MessageSingleton alloc] init];
    });
    return sharedMessageSingleton;
}

/**第4步: 保证copy时都相同*/
-(id)copyWithZone:(NSZone *)zone{
    return sharedMessageSingleton;
}







@end
